package other;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import com.alibaba.fastjson.JSON;

public class sqliteDemo {

	public static void main(String[] args) throws Exception {
		Connection conn;
		Class.forName("org.sqlite.JDBC");
		conn = DriverManager.getConnection("jdbc:sqlite:D:\\000000\\mydatabase.sqlite");

		String sql = "select  * from tab1";

		// org.apache.commons.dbutils.handlers.
		QueryRunner QueryRunner1 = new QueryRunner();

		List<Map<String, Object>> li = QueryRunner1.query(conn, sql, new MapListHandler());
System.out.println( JSON.toJSONString(li,true));
		System.out.println("ok");

	}

//	private static void exeSql(String sql) {
//
//		Connection conn = null;
//		try {
//			conn = getconn();
//		} catch (ClassNotFoundException e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		} catch (SQLException e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
//		PreparedStatement stmt = null;
//		try {
//			stmt = conn.prepareStatement(sql);
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		try {
//			stmt.executeUpdate();
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//
//	}

	public static Connection getconn() throws ClassNotFoundException, SQLException {
		Connection conn;
		Class.forName("org.sqlite.JDBC");
		conn = DriverManager.getConnection("jdbc:sqlite:c:\\test.db");
		return conn;
	}

}
